package com.wc.codeforces.思维.Sakurako_s_Field_Trip;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/24 23:01
 * @description https://codeforces.com/contest/2033/problem/C
 */
public class Main {
    /**
     * 需要和中间的比, 之间的都比较好了, 所以就可以
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] a = new int[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();


            for (int i = n / 2 - 1; i >= 1; i--) {
                int num1 = 0;
                if (a[i] == a[i + 1]) num1++;
                if (a[n - i + 1] == a[n - i + 1 - 1]) num1++;
                int num2 = 0;
                if (a[i] == a[n - i + 1 - 1]) num2++;
                if (a[n - i + 1] == a[i + 1]) num2++;
                if (num1 > num2) {
                    int tmp = a[i];
                    a[i] = a[n - i + 1];
                    a[n - i + 1] = tmp;
                }
            }
            int res = 0;
            for (int i = 1; i <= n; i++) {
                if (a[i] == a[i - 1]) res++;
            }
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
